package com.two.service.tui.service.impl;

import com.aliyun.oss.common.utils.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.two.common.entity.Tuimoney;
import com.two.common.util.CommonResult;
import com.two.service.tui.mapper.TuiMapper;
import com.two.service.tui.service.TuiService;
import com.two.service.tui.vo.TuiMoneyVo;
import com.two.service.tui.vo.TuiVo;
import org.apache.http.client.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class TuiServiceImpl implements TuiService {
  @Autowired
  private TuiMapper tuiMapper;

    @Override
    public CommonResult findAll(Integer rid,Integer currentPage, Integer pageSize,TuiVo tuiVo) {
        Page<Tuimoney> page=new Page<>(currentPage,pageSize);
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("rid",rid);

        if (StringUtils.hasText(tuiVo.getDishName())){
            queryWrapper.like("dish_name",tuiVo.getDishName());
        }

        if (tuiVo.getTuiTime()!=null){
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDateTime tuiTime = tuiVo.getTuiTime();
            String format = tuiTime.format(formatter);
            queryWrapper.like("tui_time",format);
        }
        Page<TuiVo> tuiPage=tuiMapper.selectPage(page,queryWrapper);
        System.out.println("===="+tuiPage);
        return new CommonResult(2000,"查询成功",tuiPage);
    }

    @Override
    public CommonResult insert(Tuimoney tuimoney) {
        tuiMapper.insert(tuimoney);
        return new CommonResult(2000,"添加成功",null);
    }

    @Override
    public CommonResult update(Integer id) {
        Tuimoney tuimoney=new Tuimoney();
        tuimoney.setId(id);
        tuimoney.setStatus(1);
        tuiMapper.updateById(tuimoney);
        return new CommonResult(2000,"修改成功",null);
    }

    @Override
    public CommonResult xiu(Integer id, TuiMoneyVo tuiMoneyVo) {
        Tuimoney tuimoney=new Tuimoney();
        tuimoney.setId(id);
        tuimoney.setStatus(2);
        tuimoney.setRefuseReason(tuiMoneyVo.getRefuseReason());
        tuiMapper.updateById(tuimoney);
        return new CommonResult(2000,"修改成功",null);
    }


}
